home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Text Capture FKEY / Text Capture source.cpt / Param_string.c < prev    next >
Text File  |  1991-08-19  |  1KB  |  61 lines

  1. void Param_string( StringPtr out, StringPtr format,
  2.     StringPtr p0, StringPtr p1, StringPtr p2 );
  3.  
  4. void Param_string( StringPtr out, StringPtr format,
  5.     StringPtr p0, StringPtr p1, StringPtr p2 )
  6. {
  7.     StringPtr    out_last, format_last, out_zeroth;
  8.     StringPtr    source, source_last;
  9.     Boolean        saw_hat;
  10.     
  11.     saw_hat = false;
  12.     out_zeroth = out;
  13.     out_last = out + 255;
  14.     ++out;
  15.     format_last = format + format[0];
  16.     format++;
  17.     
  18.     while ((out <= out_last) && (format <= format_last))
  19.     {
  20.         if (saw_hat)
  21.         {
  22.             saw_hat = false;
  23.             switch (*format)
  24.             {
  25.                 case '0':    source = p0; break;
  26.                 case '1':    source = p1; break;
  27.                 case '2':    source = p2; break;
  28.                 default:    source = NIL; break;    
  29.             }
  30.             if (source == NIL)
  31.             {
  32.                 *out = *format;
  33.                 ++out;
  34.             }
  35.             else
  36.             {
  37.                 source_last = source + source[0];
  38.                 ++source;
  39.                 while ((source <= source_last) && (out <= out_last))
  40.                 {
  41.                     *out = *source;
  42.                     ++out;
  43.                     ++source;
  44.                 }
  45.             }
  46.         }
  47.         else /* not saw_hat */
  48.         {
  49.             if (*format == '^')
  50.                 saw_hat = true;
  51.             else
  52.             {
  53.                 *out = *format;
  54.                 ++out;
  55.             }
  56.         }
  57.         ++format;
  58.     } /* end while */
  59.     *out_zeroth = out + 254 - out_last;
  60. }
  61.